﻿
namespace Apache.Cassandra.Client {
    using System;
    using System.ComponentModel;
    using System.Globalization;

    public class UuidConverter : TypeConverter {

        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
            if (typeof(string) == sourceType) {
                return true;
            }

            return base.CanConvertFrom(context, sourceType);
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
            string strval = value as string;
            if (null != strval) {
                return new Uuid(strval);
            }

            return base.ConvertFrom(context, culture, value);
        }
    }
}
